﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using He.Web.UI;
using He.Common;
using System.Collections.Generic;
using System.Text;
namespace He.Web.manage
{
    public partial class admin_nor : He.Web.UI.Manage
    {
        public string defaultTarget;                               //默认跳转页面
        public string langTransTxt;                                //语言版本切换
        public List<Model.channel> channel_list;           //系统频道列表
        public List<Model.plug> plug_list;                         //系统插件列表
        public bool show_plug = false;                             //是否显示系统插件
        public List<He.Model.ad_position> ad_position_list;       //广告位列表

        InputUtil Input = new InputUtil();
        He.BLL.category cbll = new BLL.category();
        He.BLL.channel scbll = new BLL.channel();
        He.BLL.article conbll = new BLL.article();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["AdminName"] != null && Session["AdminType"] != null)
                {
                    string AdminName = Session["AdminName"].ToString();
                    int AdminType = int.Parse(Session["AdminType"].ToString());
                    lblAdminName.Text = string.Format("{0} ({1}) ", AdminName, GetAdminType(AdminType));
                }
                else
                {
                    Response.Redirect(SysKeys.ADMIN_LOGIN_PAGE);
                }

                defaultTarget = "site/info.aspx?lang=" + lang;

                //判断是否跳转到修改密码页面
                if (Request.QueryString["key"] != null)
                {
                    defaultTarget = "administrator/edit_pwd.aspx?id=" + Session["AdminNo"];
                }

                #region 判断语言版本
                StringBuilder strTemp = new StringBuilder();
                List<Model.Lang> lst = new He.BLL.config().LoadConfig<List<Model.Lang>>(LangXmlPath);
                foreach (Model.Lang item in lst)
                {
                    if (item.IsShow)
                    {
                        strTemp.AppendFormat("<a {0} href=\"admin_nor.aspx?lang={1}\">{2}</a> ", item.Value == lang ? "class='red'" : "", item.Value, item.Name);
                    }
                }
                langTransTxt = strTemp.ToString();

                #endregion

                channel_list = scbll.GetModelList(string.Format("is_lock=0 and lang='{0}' order by sort_id asc", lang));
                plug_list = new BLL.config().LoadConfig<List<Model.plug>>(PlugXmlPath);
                ad_position_list = new BLL.ad_position().GetModelList(string.Format("ad_status=1 and lang='{0}'", lang));
                foreach (He.Model.plug item in plug_list)
                {
                    if (item.IsShow && item.Lang == lang)
                    {
                        show_plug = true;
                        break;
                    }
                }
            }
        }
        protected void lbtnExit_Click(object sender, EventArgs e)
        {
            Session["AdminNo"] = null;
            Session["AdminName"] = null;
            Session["AdminType"] = null;
            Session["AdminLevel"] = null;
            CookieHelper.Remove("AdminName");
            CookieHelper.Remove("AdminPwd");
            Response.Redirect(webset.web_path + SysKeys.ADMIN_LOGIN_PAGE);
        }

        protected void lbtnClearCache_Click(object sender, EventArgs e)
        {
            RemoveAllCache();
            Response.Write("<script type=\"text/javascript\">alert('清理缓存成功啦');window.location.href='admin_nor.aspx?lang=" + lang + "'</script>");
        }
    }
}
